<template>
  <transition name="dialog-fade">
    <div class="dialog-wrapper" v-if="visible" @click.self="handleClose">
      <div class="dialog-content">
        <!-- 顶部图标区域 -->
        <div class="dialog-header">
          <img :src="headerImage" alt="welcome" class="header-image">
        </div>

        <!-- 标题区域 -->
        <h2 class="dialog-title">{{ title }}</h2>

        <!-- 欢迎文本 -->
        <p class="welcome-text">{{ welcomeText }}</p>

        <!-- 快捷键提示 -->
        <div class="shortcut-tip">
          建议使用 <span class="key">Ctrl</span> + <span class="key">D</span> 收藏本站，让你不再错过任何精彩文章！
        </div>

        <!-- 服务说明 -->
        <p class="service-desc">{{ serviceDescription }}</p>

        <!-- 联系方式 -->
        <p class="contact-info">{{ contactInfo }}</p>

        <!-- 按钮 -->
        <button class="dialog-button" @click="handleClose">
          {{ buttonText }}
        </button>
      </div>
    </div>
  </transition>
</template>

<script>
import CacheUtil from "@/utils/CacheUtil";
import constantsData from "@/constants";

export default {
  name: 'WelcomeDialog',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
  },
  data() {
    return JSON.parse(constantsData().welcomeDialog)
  },
  methods: {
    handleClose() {
      // 获取当前时间
      const nowTimestamp = Date.now();
      const endTime = new Date();
      endTime.setHours(endTime.getHours() + this.vanishingTime);
      const endTimestamp = endTime.getTime()
      const overdue = {
        starTime: nowTimestamp,
        endTime: endTimestamp,
        vanishingTime: this.vanishingTime
      }
      CacheUtil.setItem('vanishingTime', overdue)
      this.$emit('update:visible', false)
    }
  }
}
</script>

<style scoped>
.dialog-wrapper {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.dialog-content {
  width: 420px;
  background: var(--card-bg);
  border-radius: 12px;
  padding: 0 24px 24px;
  text-align: center;
  position: relative;
  box-shadow: 0 4px 16px var(--shadow-color);
  animation: dialog-show 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.dialog-header {
  margin: -60px auto 20px;
  width: 120px;
  height: 120px;
  background: var(--card-bg);
  border-radius: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px var(--shadow-color);
}

.header-image {
  width: 80px;
  height: 80px;
  object-fit: contain;
}

.dialog-title {
  font-size: 20px;
  font-weight: bold;
  color: var(--text-color);
  margin-bottom: 12px;
  background: linear-gradient(45deg, var(--primary-color), #00c6ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.welcome-text {
  font-size: 16px;
  color: var(--text-color);
  margin-bottom: 16px;
}

.shortcut-tip {
  background: var(--hover-color);
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 16px;
  color: var(--text-color);
  font-size: 14px;
  line-height: 1.5;
  border: 1px solid var(--border-color);
}

.key {
  display: inline-block;
  padding: 2px 6px;
  background: var(--primary-color);
  color: white;
  border-radius: 4px;
  margin: 0 2px;
  font-weight: 500;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.service-desc {
  color: var(--secondary-color);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 12px;
  padding: 0 20px;
}

.contact-info {
  color: var(--secondary-color);
  font-size: 14px;
  margin-bottom: 24px;
  background: var(--hover-color);
  display: inline-block;
  padding: 4px 12px;
  border-radius: 15px;
}

.dialog-button {
  width: 100%;
  height: 44px;
  background: linear-gradient(45deg, var(--primary-color), #00c6ff);
  color: white;
  border: none;
  border-radius: 22px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.dialog-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.dialog-button:active {
  transform: translateY(0);
}

/* 动画效果 */
.dialog-fade-enter-active,
.dialog-fade-leave-active {
  transition: opacity 0.3s;
}

.dialog-fade-enter,
.dialog-fade-leave-to {
  opacity: 0;
}

@keyframes dialog-show {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* 响应式处理 */
@media (max-width: 480px) {
  .dialog-content {
    width: 90%;
    max-width: 360px;
    padding: 0 16px 20px;
  }

  .dialog-header {
    width: 100px;
    height: 100px;
    margin: -50px auto 16px;
  }

  .header-image {
    width: 60px;
    height: 60px;
  }

  .dialog-title {
    font-size: 18px;
  }

  .welcome-text {
    font-size: 15px;
  }

  .shortcut-tip,
  .service-desc,
  .contact-info {
    font-size: 13px;
  }

  .dialog-button {
    height: 40px;
    font-size: 15px;
  }
}
</style>
